package com.tcd.explore.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.tcd.explore.pojo.HumanInjuryInfo;
import com.tcd.explore.service.HumanInjuryInfoService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 人伤信息详情表 前端控制器
 * </p>
 *
 * @author Jarle
 * @since 2021-05-25
 */
@RestController
@CrossOrigin
@RequestMapping("/generator")
public class HumanInjuryInfoController {
    @Autowired
    HumanInjuryInfoService humaninfo;

    @RequestMapping("/humanInjuryInfo")
    public List<HumanInjuryInfo> humanInjuryInfoall(String claimId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("claim_main_id", claimId);
        return humaninfo.list(wrapper);
    }

    @RequestMapping("/humanInjuryInfoadd")
    public Integer humanInjuryInfoadd(@RequestBody HumanInjuryInfo human) {
        Long id = IdWorker.getId();
        String num = 450 + "" + id.intValue();
        Integer i = 0;
        if (num.indexOf('-') != -1) {
            num = num.substring(0, num.lastIndexOf("-")) + num.substring(num.lastIndexOf("-") + 1, num.length() - 1);
        }
        i = Integer.parseInt(num.substring(0, 9));
        human.setHumaninjuryId(Integer.valueOf(num.substring(0, 9)));
        return humaninfo.saveOrUpdate(human) == true ? i : 0;
    }

    @RequestMapping("/humanInjurystatusedit")
    public boolean humanInjurystatusedit(String claimmainid, String lossstatus) {
        return humaninfo.update(claimmainid, lossstatus);
    }

    @RequestMapping("/humanInjurydel")
    public boolean humanInjurydel(String hid) {
        return humaninfo.removeById(hid);
    }

    @RequestMapping("/humanInjuryedit")
    public boolean humanInjuryedit(@RequestBody HumanInjuryInfo human) {
        return humaninfo.updateById(human);
    }
}

